package com.wc.算法提高课.D第四章_高级数据结构.AC自动机.单词;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/29 22:50
 * @description https://www.acwing.com/problem/content/1287/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010, M = 210, idx = 0;
    static char[] s;
    static int[][] tr = new int[N][26];
    static int[] q = new int[N], ne = new int[N], cnt = new int[N], id = new int[M];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            s = sc.next().toCharArray();
            insert(i);
        }
        build();
        // 拓扑序的你序列, 计算最前面的个数, 需要从后往前计算
        for (int i = idx; i >= 1; i--) cnt[ne[q[i]]] += cnt[q[i]];
        for (int i = 1; i <= n; i++) out.println(cnt[id[i]]);
        out.flush();
    }

    static void build() {
        int hh = 1, tt = 0;
        for (int i = 0; i < 26; i++) {
            if (tr[0][i] > 0) q[++tt] = tr[0][i];
        }
        while (hh <= tt) {
            int t = q[hh++];
            for (int i = 0; i < 26; i++) {
                int p = tr[t][i];
                if (p == 0) tr[t][i] = tr[ne[t]][i];
                else {
                    ne[p] = tr[ne[t]][i];
                    q[++tt] = p;
                }
            }
        }
    }

    static void insert(int x) {
        int p = 0;
        for (char c : s) {
            int t = c - 'a';
            if (tr[p][t] == 0) tr[p][t] = ++idx;
            p = tr[p][t];
            cnt[p]++;
        }

        id[x] = p;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
